Skip to contentSkip to conversation

Change in openvpn[master]: phase2_tcp_server: fix Coverity issue "Dereference after null check"

Openvpn-devel In review flichtenheld (Code Review) 2 participants 9 messages Jan 9, 2024 – Mar 25, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1704798536000.I8ef199463d46303129a3f563fd9eace780a58b8a@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/490?usp=email

to review the following change.

Change subject: phase2_tcp_server: fix Coverity issue "Dereference after null check"
......................................................................

phase2_tcp_server: fix Coverity issue "Dereference after null check"

As Coverity says:
Either the check against null is unnecessary, or there may be a null pointer dereference.
In phase2_tcp_server: Pointer is checked against null but then dereferenced anyway

The check is probably not required since we have an ASSERT(sig_info) in the caller. But I really didn't want to remove the check. So make the code consistent instead.

Change-Id I8ef199463d46303129a3f563fd9eace780a58b8a

---
M src/openvpn/socket.c

1 file changed, 4 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/90/490/1

src/openvpn/socket.c +4 -1
index 480f4e5..c158de1 100644
@@ -2031,7 +2031,10 @@
                                         false);
             if (!socket_defined(sock->sd))
             {
-                register_signal(sig_info, SIGTERM, "socket-undefiled");
+                if (signal_received)
+                {
+                    register_signal(sig_info, SIGTERM, "socket-undefined");
+                }
                 return;
             }
             tcp_connection_established(&sock->info.lsa->actual);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/490?usp=email )

Change subject: phase2_tcp_server: fix Coverity issue "Dereference after null check"
......................................................................

Patch Set 1: Code-Review-1

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/490/comment/49bd721f_a0919cda :
PS1, Line 2034: if (signal_received)
I do not like checking signal_received here if what we're really interested is sig_info (I do understand that bother are NULL or none of them, but this way the code is still more confusing than necessary).

This said, if we know sig_info is never NULL anyway, because there is only a single caller, maybe a better fix would be

```
ASSERT(sig_info);
volatile int *signal_received = &sig_info->signal_received;
```

at the beginning of the function.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 19 Jan 2024 08:27:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/490?usp=email )

Change subject: phase2_tcp_server: fix Coverity issue "Dereference after null check"
......................................................................

Patch Set 1:

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/490/comment/2bf317a9_1cc5b58d :
PS1, Line 2034: if (signal_received)

Quoted 1 line

I do not like checking signal_received here if what we're really interested is sig_info (I do un […]

Acknowledged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Mon, 22 Jan 2024 10:06:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/490?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: phase2_tcp_server: fix Coverity issue "Dereference after null check"
......................................................................

phase2_tcp_server: fix Coverity issue "Dereference after null check"

As Coverity says:
Either the check against null is unnecessary, or there may be a null pointer dereference.
In phase2_tcp_server: Pointer is checked against null but then dereferenced anyway

There is only one caller (link_socket_init_phase2) and it already has an ASSERT(sig_info). So use that here was well.

v2:
- fix cleanly by actually asserting that sig_info is defined

Change-Id I8ef199463d46303129a3f563fd9eace780a58b8a

---
M src/openvpn/socket.c

1 file changed, 3 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/90/490/2

src/openvpn/socket.c +3 -2
index 480f4e5..387cb40 100644
@@ -2005,7 +2005,8 @@
 phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic,
                   struct signal_info *sig_info)
 {
-    volatile int *signal_received = sig_info ? &sig_info->signal_received : NULL;
+    ASSERT(sig_info);
+    volatile int *signal_received = &sig_info->signal_received;
     switch (sock->mode)
     {
         case LS_MODE_DEFAULT:
@@ -2031,7 +2032,7 @@
                                         false);
             if (!socket_defined(sock->sd))
             {
-                register_signal(sig_info, SIGTERM, "socket-undefiled");
+                register_signal(sig_info, SIGTERM, "socket-undefined");
                 return;
             }
             tcp_connection_established(&sock->info.lsa->actual);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld.

plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/490?usp=email )

Change subject: phase2_tcp_server: fix Coverity issue "Dereference after null check"
......................................................................

Patch Set 2: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 25 Mar 2024 01:13:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#6 lore raw

PATCH v2 1/1 phase2_tcp_server: fix Coverity issue "Dereference after null check"

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

As Coverity says:
Either the check against null is unnecessary, or there may be a null pointer dereference.
In phase2_tcp_server: Pointer is checked against null but then dereferenced anyway

There is only one caller (link_socket_init_phase2) and it already has an ASSERT(sig_info). So use that here was well.

v2:
- fix cleanly by actually asserting that sig_info is defined

Change-Id I8ef199463d46303129a3f563fd9eace780a58b8a

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/490
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>

src/openvpn/socket.c +3 -2
index 480f4e5..387cb40 100644
@@ -2005,7 +2005,8 @@
 phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic,
                   struct signal_info *sig_info)
 {
-    volatile int *signal_received = sig_info ? &sig_info->signal_received : NULL;
+    ASSERT(sig_info);
+    volatile int *signal_received = &sig_info->signal_received;
     switch (sock->mode)
     {
         case LS_MODE_DEFAULT:
@@ -2031,7 +2032,7 @@
                                         false);
             if (!socket_defined(sock->sd))
             {
-                register_signal(sig_info, SIGTERM, "socket-undefiled");
+                register_signal(sig_info, SIGTERM, "socket-undefined");
                 return;
             }
             tcp_connection_established(&sock->info.lsa->actual);
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: phase2_tcp_server: fix Coverity issue 'Dereference after null check'

This is arguably a correct fix, though we could go a bit further in terms of refactoring and fully get rid of signal_received - if my understanding of the code is correct, it's only passed to a single function (socket_listen_accept()), which is only called from here - so "just pass on sig_info and use that" would be a bit less convoluted.

But that's refactoring, so for future master...

Lightly tested on the server framework.

Your patch has been applied to the master and release/2.6 branch.

commit e8c629fe64c67ea0a8454753be99db44df7ce53e (master) commit 5591af17694d98054da2cdf4cfd42508a8a4fb8e (release/2.6)

Author: Frank Lichtenheld
Date:   Mon Mar 25 08:14:48 2024 +0100
     phase2_tcp_server: fix Coverity issue 'Dereference after null check'

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg28452.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#8 lore raw

[Openvpn-devel] [XS] Change in openvpn[master]: phase2_tcp_server: fix Coverity issue 'Dereference after null check'

In reply to a message not in the archive

cron2 has uploaded a new patch set (#3) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/490?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by plaisthos

Change subject: phase2_tcp_server: fix Coverity issue 'Dereference after null check'
......................................................................

phase2_tcp_server: fix Coverity issue 'Dereference after null check'

As Coverity says:
Either the check against null is unnecessary, or there may be a null pointer dereference.
In phase2_tcp_server: Pointer is checked against null but then dereferenced anyway

There is only one caller (link_socket_init_phase2) and it already has an ASSERT(sig_info). So use that here was well.

v2:
- fix cleanly by actually asserting that sig_info is defined

Change-Id I8ef199463d46303129a3f563fd9eace780a58b8a

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28452.html

---
M src/openvpn/socket.c

1 file changed, 3 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/90/490/3

src/openvpn/socket.c +3 -2
index 57eaee2..d2b82d5 100644
@@ -2005,7 +2005,8 @@
 phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic,
                   struct signal_info *sig_info)
 {
-    volatile int *signal_received = sig_info ? &sig_info->signal_received : NULL;
+    ASSERT(sig_info);
+    volatile int *signal_received = &sig_info->signal_received;
     switch (sock->mode)
     {
         case LS_MODE_DEFAULT:
@@ -2031,7 +2032,7 @@
                                         false);
             if (!socket_defined(sock->sd))
             {
-                register_signal(sig_info, SIGTERM, "socket-undefiled");
+                register_signal(sig_info, SIGTERM, "socket-undefined");
                 return;
             }
             tcp_connection_established(&sock->info.lsa->actual);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#9 lore raw

[Openvpn-devel] [XS] Change in openvpn[master]: phase2_tcp_server: fix Coverity issue 'Dereference after null check'

In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/490?usp=email )

Change subject: phase2_tcp_server: fix Coverity issue 'Dereference after null check'
......................................................................

phase2_tcp_server: fix Coverity issue 'Dereference after null check'

As Coverity says:
Either the check against null is unnecessary, or there may be a null pointer dereference.
In phase2_tcp_server: Pointer is checked against null but then dereferenced anyway

There is only one caller (link_socket_init_phase2) and it already has an ASSERT(sig_info). So use that here was well.

v2:
- fix cleanly by actually asserting that sig_info is defined

Change-Id I8ef199463d46303129a3f563fd9eace780a58b8a

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28452.html

---
M src/openvpn/socket.c

1 file changed, 3 insertions(+), 2 deletions(-)
src/openvpn/socket.c +3 -2
index 57eaee2..d2b82d5 100644
@@ -2005,7 +2005,8 @@
 phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic,
                   struct signal_info *sig_info)
 {
-    volatile int *signal_received = sig_info ? &sig_info->signal_received : NULL;
+    ASSERT(sig_info);
+    volatile int *signal_received = &sig_info->signal_received;
     switch (sock->mode)
     {
         case LS_MODE_DEFAULT:
@@ -2031,7 +2032,7 @@
                                         false);
             if (!socket_defined(sock->sd))
             {
-                register_signal(sig_info, SIGTERM, "socket-undefiled");
+                register_signal(sig_info, SIGTERM, "socket-undefined");
                 return;
             }
             tcp_connection_established(&sock->info.lsa->actual);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/490?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8ef199463d46303129a3f563fd9eace780a58b8a
Gerrit-Change-Number: 490
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged